package com.hu.zhcc.shiro.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.dao.IndexMapper;
import com.hu.zhcc.shiro.entity.bo.Index;
import com.hu.zhcc.shiro.entity.vo.IndexVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndexServiceImpl implements IndexService{

    @Autowired
    private IndexMapper indexMapper;

    @Override
    public boolean AddIndex(Index index) {
            return indexMapper.insert(index)>0;
    }
    //分页查询
    @Override
    public PageInfo<Index> pageQuery(IndexVO indexVO) {
        PageHelper.startPage(indexVO.getPageNum(),indexVO.getPageSize());
        List<Index> byCondition = indexMapper.findByCondition(indexVO.getQueryString());
        PageInfo<Index> checkItemPageInfo = new PageInfo<>(byCondition);
        return checkItemPageInfo;
    }

    @Override
    public boolean updateIndex(Index index) {
        return indexMapper.updateByPrimaryKey(index)>0;
    }

    @Override
    public boolean removeIndex(Short id) {
        return indexMapper.deleteByPrimaryKey(id)>0;
    }
}
